﻿namespace Cap
{
    public static class EndpointBuilderExtensions
    {
        public static void Use(this IEndpointBuilder builder, Func<CloudEventContext, Func<Task>, Task> middleware)
        {
            builder.Use(next =>
            {
                return async context =>
                {
                    await middleware(context, () => next(context));
                };
            });
        }

        public static void Run(this IEndpointBuilder builder, EventDelegate handler)
        {
            builder.Use(_ =>
            {
                return async context =>
                {
                    await handler(context);
                };
            });
        }
    }
}
